package com.jin.flashsaled.utils;


import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {

    //前端加密的salt
    private static final String salt="1a2b3c4d";
    //对数据进行加密操作
    public static String md5(String input)
    {
        return DigestUtils.md5Hex(input);
    }
    //第一层加密,在前端进行加密
    public static String inputPasswordToFromPassword(String inputPassword)
    {
        String str=""+salt.charAt(0)+salt.charAt(1)+inputPassword+salt.charAt(3)+salt.charAt(4);
        return md5(str);
    }

    //第二层加密,在后端进行加密
    public static String fromPasswordToDbPassword(String fromPassword, String dbSalt)
    {

        String str=""+dbSalt.charAt(0)+dbSalt.charAt(1)+fromPassword+dbSalt.charAt(3)+dbSalt.charAt(4);
        return md5(str);
    }

    //调用，前端密码到数据库密码
    public static String inputPasswordToDbPassword(String inputPassword, String dbSalt)
    {

        String fromPassword=inputPasswordToFromPassword(inputPassword);
        String dbPassword=fromPasswordToDbPassword(fromPassword,dbSalt);
        return dbPassword;
    }

    public static void main(String[] args)
    {
        System.out.println(inputPasswordToFromPassword("123456"));
        System.out.println(fromPasswordToDbPassword(inputPasswordToFromPassword("123456"),"123456"));
        System.out.println(inputPasswordToDbPassword("123456","123456"));
    }






}
